package service

import (
	"go-demo/dao"
	"go-demo/model"
)

// 获取视频流
func GetFeed() []model.Video {
	//获取所有的视频信息
	videos, _ := dao.GetAllVideo()
	//补充对应的用户信息
	videoList := GetVideoList(videos)
	return videoList
}

// 补充视频对应的用户信息
func GetVideoList(videos []model.Video) (videoList []model.Video) {
	var video model.Video
	for k := range videos {
		user, _ := dao.GetUserByID(videos[k].UserId)
		//拷贝自身属性
		video = model.Video{
			Id:            videos[k].Id,
			UserId:        videos[k].UserId,
			PlayUrl:       videos[k].PlayUrl,
			CoverUrl:      videos[k].CoverUrl,
			FavoriteCount: videos[k].FavoriteCount,
			CommentCount:  videos[k].CommentCount,
			IsFavorite:    videos[k].IsFavorite,
			Title:         videos[k].Title,
			//拷贝用户属性
			Author: model.User{
				Id:              user.Id,
				Name:            user.Name,
				FollowCount:     user.FollowCount,
				FollowerCount:   user.FollowerCount,
				IsFollow:        user.IsFollow,
				Avatar:          user.Avatar,
				BackgroundImage: user.BackgroundImage,
				Signature:       user.Signature,
				TotalFavourite:  user.TotalFavourite,
				WorkCount:       user.WorkCount,
				FavoriteCount:   user.FavoriteCount},
		}
		videoList = append(videoList, video)
	}
	return videoList
}
